home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Draw.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  47.4 KB  |  1,261 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    Draw.Lib
  5. #
  6. #    Contains:    Tasks to help do testing of drawing operations
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #    <1.0.10>     12/2/93    KTA        CheckObjectStruct() doesn't choke on kMultiClickDrag tools
  19. #                                    anymore.
  20. #     <1.0.9>    11/19/93    NAGA    Modify TCS format
  21. #     <1.0.8>     8/30/93    KTA        Updated task headers and parameters.
  22. #     <1.0.7>     8/25/93    KTA        Added support for parity checking the TCS stack.
  23. #     <1.0.6>      8/3/93    KTA        DrawObject()- Fixed bug where directCoord Tools weren't setting
  24. #                                    any attributes.
  25. #     <1.0.4>      6/8/93    NAGA    unmark tasks that are not published
  26. #        <2+>      6/8/93    NAGA    unmark tasks that are not published
  27. #        <1+>     5/21/93    NAGA    Adding header and porting old files to follow new standards
  28. #
  29. # ****************************************************************************
  30. #
  31.  
  32. ########################################################################
  33. #                            External libraries 
  34. #=======================================================================
  35. Libraries  "Palette.Lib", "String.Lib","OutPut.lib", "TCS.Lib", "Geometry.Lib","UserInterface.Lib";
  36.  
  37. #########################################################################
  38. #                        InitDraw()
  39. #========================================================================
  40. # Author:        KTA
  41. # Description:    Initializes the Draw globals. 
  42. # Parameters:    None
  43. # Returns:        Nada
  44. # Examples:        InitDraw();
  45. # Assumptions:    
  46. #========================================================================
  47. # History:
  48. #
  49. #########################################################################
  50. TASK InitDraw()
  51. begin
  52.     ##############  Task References   ############
  53.     global gSetLine             := Task SetLine;        # Requires VU 2.0
  54.     global gSetColor             := Task SetColor;        # Requires VU 2.0
  55.     global gSetPattern             := Task SetPattern;        # Requires VU 2.0
  56.  
  57.     ############## Tool Type Defines  ############
  58.     global kClick                 := 1;
  59.     global kDrag                 := 2;
  60.     global kDragClick             := 3;
  61.     global kMultiDrag            := 4;
  62.     global kMultiClick             := 5;
  63.     global kMultiClickDrag         := 6;
  64.  
  65.     ############## Palette Type Defines  ########
  66.     global kPalDocWind             := 1;
  67.     global kPalWind             := 2;
  68.     global kPopUpPal             := 3;
  69.  
  70.     ############## Script Contants  ############
  71.     global gWindowInset         := {0,20,20,20};        # Inset to wind to get content region
  72.     global gScreenInset         := {0,20,0,0};            # Inset to screen
  73.     global gBoundingRect         := {};                    # 
  74.     global gVoidRect             := {};                    # Rect not to draw in - coordinates should be RelativeToWindow
  75.     global gLineWeights         := {};                    # Line Weights
  76.     global gNumPoints            := 6;                    # Number of points for all multipoint tools
  77.     global gDrawObject            := 0;                    # Object Number in a given suite (incremented by DrawObject)
  78. end;
  79.  
  80. #########################################################################
  81. #            CheckObjectStruct(pObjectStruct)
  82. #========================================================================
  83. # Author:        Kevin Avoy
  84. # Description:    Check validity of elements in pObjectStruct.
  85. # Parameters:    pObjectStruct -     the objectStruct to check
  86. # Returns:        0 - objectStruct is hosed
  87. #                1 - objectStruct is OK
  88. # Example:    returnVal := CheckObjectStruct(pObjectStruct);
  89. #========================================================================
  90. # History:
  91. # KTA    12/01/93    kMultiClickDrag tools weren't supported added 
  92. #                    elemType <= 6 (bug #1117685)
  93. #########################################################################
  94. TASK CheckObjectStruct(pObjectStruct)
  95. begin
  96.     if (global gDebugFlag)
  97.         println "----- CheckObjectStruct() - Draw.lib --------";
  98.     global gNumPoints;
  99.     returnVal := 1;
  100.     
  101.     if not(Card(pObjectStruct) = 5)
  102.     begin
  103.         Println "!@#$% CheckObjectFailure - Card(pObjectStruct) - ", Card(pObjectStruct);
  104.         returnVal := 0;
  105.     end;
  106.     
  107.     ## Tool Struct
  108.     elemStruct    := GetElemStruct(pObjectStruct);
  109.     if not(Card(elemStruct) = 6)
  110.     begin
  111.         Println "!@#$% CheckObjectFailure - Card(elemStruct) - ", Card(elemStruct);
  112.         returnVal := 0;
  113.     end;
  114.  
  115.     ## ToolType
  116.     elemType := GetElemType(elemStruct);
  117.     if not (elemStruct = 'Random')
  118.     begin
  119.         if not((elemType >= 0) and (elemType <= 6) )
  120.         begin
  121.             Println "!@#$% CheckObjectFailure - elemType - ", ElemType;
  122.             returnVal := 0;
  123.         end;
  124.     end;
  125.     
  126.     ## Tool Name
  127.     elemName := GetElemName(elemStruct);
  128.     if not (elemStruct = 'Random')
  129.     begin
  130.         if not( TypeOf(elemName) = "string" )
  131.         begin
  132.             Println "!@#$% CheckObjectFailure - elemName - ", elemName;
  133.             returnVal := 0;
  134.         end;
  135.     end;
  136.     
  137.     ## DoubleClick
  138.     elemDblClk := GetElemDblClk(elemStruct);
  139.     if not (elemStruct = 'Random')
  140.     begin
  141.         if not((elemDblClk = 0) or (elemDblClk = 1) )
  142.         begin
  143.             Println "!@#$% CheckObjectFailure - elemDblClk - ", elemDblClk;
  144.             returnVal := 0;
  145.         end;
  146.     end;
  147.     
  148.     ## Pointlist
  149.     pointList := GetPointList(pObjectStruct);
  150.     if (global gDebugFlag)
  151.         println "This is the pointlist",pointList;
  152.     (*    
  153.     if not((Card(pointList) = gNumPoints) or (Card(pointList) = elemType))
  154.     begin
  155.         Println "!@#$% CheckObjectFailure - pointList - ",  pointList;
  156.         returnVal := 0;
  157.     end;
  158.  
  159.     ## Line
  160.     theLine    := GetLine(pObjectStruct);
  161.     if not((TypeOF(theLine) = "list") and (Card(theLine) = 3) or (theLine = 0))
  162.     begin
  163.         Println "!@#$% CheckObjectFailure - theLine - ", theLine;
  164.         returnVal := 0;
  165.     end;
  166.  
  167.     ## Color
  168.     theCol := GetColor(pObjectStruct);
  169.     if not((TypeOF(theCol) = "list") and (Card(theCol) = 3) or (theCol = 0))
  170.     begin
  171.         Println "!@#$% CheckObjectFailure - theCol - ", theCol;
  172.         returnVal := 0;
  173.     end;
  174.     
  175.     ## Pattern
  176.     thePat := GetPattern(pObjectStruct);
  177.     if not((TypeOF(thePat) = "list") and (Card(thePat) = 3) or (thePat = 0))
  178.     begin
  179.         Println "!@#$% CheckObjectFailure - thePat - ", thePat;
  180.         returnVal := 0;
  181.     end;
  182. *)
  183.     if (global gDebugFlag) # Set gDebugFlag to TRUE to output variables for debugging 
  184.     begin
  185.         Println "======= DebugStr - CheckObject() in Draw.Lib ======";
  186.         Println "    pObjectStruct - ", {pObjectStruct};
  187.         Println "    elemStruct - ", {elemStruct};
  188.         Println "    elemType - ", {elemType};
  189.         Println "    elemName - ", {elemName};
  190.         Println "    elemDblClk - ", {elemDblClk};
  191.         Println "    pointList - ", {pointList};
  192.     end;
  193.  
  194.     return returnVal;
  195. end;    # CheckObjectStruct()
  196.  
  197. #########################################################################
  198. #                DrawObject(pObjectStruct, pSpecifier)
  199. #========================================================================
  200. # Author:        David Matzner / Kevin Avoy
  201. # Description:    Main routine in the Draw Libraries.  Calls all subroutines
  202. #                necessary to draw a given object, passing the appropriate 
  203. #                elements from the pObjectStruct input param.
  204. # Parameters:    pObjectStruct :=     {
  205. #                                    {ToolStruct},
  206. #                                    {PointList},
  207. #                                    {PatternStruct}, 
  208. #                                    {LineStruct},
  209. #                                    {ColorStruct}
  210. #                                    };
  211. #                pSpecifier - Specifies the window (or Rect) to draw in)
  212. # Returns:        1 - exercises went OK
  213. #                0 - error in drawing object
  214. # Examples:    noError := DrawObject(objectStruct,specifier);
  215. # DrawObject({global SelectTool, {{25,15}}, {12,2 ,’Pattern’}, 0, ‘Random’});
  216. #========================================================================
  217. # History:
  218. # KTA    8/3/92 Fixed bug where directCoord Tools weren't setting any attributes
  219. #########################################################################
  220. TASK DrawObject(pObjectStruct := {}, pSpecifier := 0) begin
  221.     global kClick, kDrag,kDragClick, kMultiDrag, kMultiClickDrag, kMultiClick,gToolsThatUseLineWeight, gDrawObject;
  222.     gDrawObject := gDrawObject + 1;  # Increment the object number for TCS info
  223.     TempMouse := MouseSpeed(5);
  224.     TempTargetCheck := global gTargetCheck;
  225.     global gTargetCheck := 0;
  226.     if (global gDebugFlag)
  227.         println "----- DrawObject() - Draw.lib --------";
  228.     
  229.     ## Call accessors to access object struct
  230.     ToolStruct    := GetElemStruct(pObjectStruct);
  231.     if (ToolStruct = 'Random')
  232.     begin
  233.         pObjectStruct := InsertElemStruct(SetTool(ToolStruct,0),pObjectStruct); # insert a random one but don't select it.
  234.         ToolStruct    := GetElemStruct(pObjectStruct);
  235.         if (global gDebugFlag)
  236.             println "----- This is the ObjectStruct after inserting Toolstruct -", pObjectStruct;
  237.     end;
  238.     elemPalNum := GetPalNum(ToolStruct);
  239.     elemType := GetElemType(ToolStruct);
  240.     elemName := GetElemName(ToolStruct);
  241.     elemDblClk := GetElemDblClk(ToolStruct);
  242.     elemNum := GetElemNum(ToolStruct); 
  243.     SetAttributeFlag := GetSetAttribute(ToolStruct);
  244.  
  245.     pointList := SetPointList(pObjectStruct, pSpecifier);
  246.     pObjectStruct := InsertPointList(pointList, pObjectStruct);
  247.  
  248.     returnVal := CheckObjectStruct(pObjectStruct); #
  249.     if (returnVal) 
  250.     begin
  251.         if (TypeOf(elemPalNum) = 'list')    ## Handle Coordinate tools
  252.             returnVal := PalettePicker(ToolStruct);
  253.         else
  254.             SetTool(ToolStruct,,gDrawObject);
  255.         ###########################################################
  256.         #### Call to set object attributes and update pObjectStruct
  257.         ###########################################################
  258.         if(not(SetAttributeFlag) or ((Typeof(SetAttributeFlag) = 'string') and (Card(GetAttributes(ToolStruct)) = 1)))
  259.         begin
  260.             pObjectStruct := InsertPattern(0, pObjectStruct)    ;# Insert NIL patternStruct
  261.             pObjectStruct := InsertColor(0, pObjectStruct)    ;# Insert NIL ColorStruct
  262.             pObjectStruct := InsertLine(0, pObjectStruct)    ;# Insert NIL LineStruct
  263.         end;
  264.         else if(SetAttributeFlag = 1)
  265.             pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
  266.     
  267.         if(elemType)    # Tool Type is zero because we don't want to draw an object
  268.         begin
  269.             # inform the user of the object we are going to draw
  270.             pointStr := PointListToStr(pointList);            # put pointList into a string
  271.             str := "-- Drawing object defined by points {pointStr}";
  272.             if (elemType = kClick) 
  273.                 LogStr(Str);
  274.             else 
  275.             begin
  276.                 # inform user of actions to take place before/during/after each move
  277.                 if ((elemType = kDrag) or (elemType = kMultiDrag))
  278.                     LogStr("{str} Will hold mouse down during move");
  279.                 else if (elemType = kMultiClickDrag)
  280.                     LogStr("{str} Will hold mouse down during each move and release at each destination point");
  281.                 else if (elemType = kMultiClick)
  282.                     LogStr("{str} Will click at each point");
  283.             end;
  284.         
  285.             temp := global gDisableAllLogging;
  286.             if not(global gDebugFlag)
  287.                 gDisableAllLogging := 1;
  288.         
  289.             # Call the UseTool Routines
  290.             thePt := pointList[1];                # get first point
  291.             MoveRelativeToWindow(thePt[1],thePt[2],pSpecifier);    # move to the first point and set relativeFlag
  292.             pointList := remove(1,pointList);  # remove first point from list - we already used it
  293.             if (elemType = kClick)
  294.                 returnVal := UseClickTool();
  295.                 else if (elemType = kDrag) 
  296.                     returnVal := UseDragTool( pointList[1], pSpecifier, ,elemDblClk );
  297.                     else if (elemType = kDragClick) 
  298.                         returnVal := UseDragClickTool( pointList, pSpecifier, ,elemDblClk );
  299.                         else if (elemType = kMultiDrag)
  300.                             returnVal := UseMultiDragTool( pointList, pSpecifier, elemDblClk );
  301.                             else if (elemType = kMultiClick)
  302.                                 returnVal := UseMultiClickTool( pointList, pSpecifier, elemDblClk );
  303.                                 else if (elemType = kMultiClickDrag)
  304.                                     returnVal := UseMultiClickDragTool( pointList, pSpecifier, elemDblClk );
  305.                                     else begin
  306.                                         LogStr("No tool function declared for tool type {elemType}");
  307.                                         returnVal := 0;
  308.                                     end;
  309.             gDisableAllLogging := temp;
  310.         end;
  311.         else
  312.             Println "Tool Type for this tool is 0, so no object drawn.";
  313.  
  314.     if (DialogCheck('',1))        # Check for any dialogs
  315.         returnVal := 0;
  316.     if (returnVal)
  317.     begin
  318.         if(SetAttributeFlag = 2) or (Typeof(SetAttributeFlag) = 'string')
  319.             pObjectStruct := SetAttributes(pObjectStruct,gDrawObject);
  320.         ### To handle text entry
  321.         if(Typeof(SetAttributeFlag) = 'string')
  322.             TypeStr(SetAttributeFlag);
  323.     
  324.         if (returnVal)
  325.         begin
  326.             LogStr("----- Finished drawing object -----");
  327.             returnVal := pObjectStruct;
  328.         end;
  329.     end;
  330.     else
  331.         LogStr("!@#$% Failed to draw object !@#$%");
  332.     end;    
  333.         Println "• theObject  - ", returnVal;
  334.         println "-----------------------------------";
  335.         println ;
  336.         MouseSpeed(TempMouse);
  337.         gTargetCheck := TempTargetCheck;
  338.      return(returnVal);
  339. end; # DrawObject()
  340.  
  341. #########################################################################
  342. #                SetAttributes(pObjectStruct,pDrawObject)
  343. #========================================================================
  344. # Author:        Kevin Avoy
  345. # Description:    This task takes a complete objectStruct as a parameter, it will
  346. #                determine if the tool being used to draw with can set various
  347. #                attributes (patterns, lines, and colors).  If so the appropriate
  348. #                tasks will be called and the actual attribute structs used will
  349. #                be inserted into the objectStruct prior to returning.
  350. # Parameters:    pObjectStruct - a complete objectStruct - note some elements will
  351. #                                evaluate to 0 or random upon entry - the random 
  352. #                                elements will be replaced with actual atribute  
  353. #                                struct prior to exiting. Elements that are 0 will
  354. #                                not be set.
  355. #                pDrawObject -     This is the number that is used to tie together
  356. #                                all elements that make up an object for TCS  
  357. #                                logging purposes.
  358. # Returns:    pObjectStruct  - Setting attributes went OK
  359. #            0 - error in - Setting attributes
  360. # Examples:    
  361. #========================================================================
  362. # History:
  363. #
  364. #########################################################################
  365. TASK SetAttributes(pObjectStruct,pDrawObject)
  366. begin
  367.     global gSetPattern, gSetLine, gSetColor;
  368.     elemStruct    := GetElemStruct(pObjectStruct);
  369.     elemNum := GetElemNum(ElemStruct); 
  370.     ###########################################################
  371.     #### Call to set object attributes and update pObjectStruct
  372.     ###########################################################
  373.     ##### SetPattern ######
  374.     if(GetPatternFlag(elemStruct))
  375.     begin
  376.         thePat := GetPattern(pObjectStruct);
  377.         if (thePat)
  378.         begin
  379.             myPat :=  Call(gSetPattern, thePat,,pDrawObject);
  380.             pObjectStruct := InsertPattern(myPat, pObjectStruct);
  381.         end;
  382.         if (global gDebugFlag)
  383.             println "This is the pObjectStruct after SetPattern - ", pObjectStruct;
  384.     end;
  385.     else
  386.     begin
  387.         if (global gDebugFlag)
  388.             LogStr("This is not a pattern tool");
  389.         pObjectStruct := InsertPattern(0, pObjectStruct);
  390.     end;
  391.     ##### SetLine ###### 
  392.     if(GetLineFlag(elemStruct))
  393.     begin
  394.         theLine := GetLine(pObjectStruct);
  395.         if (theLine)
  396.         begin
  397.             myLine :=  Call(gSetLine, theLine,,pDrawObject);
  398.             pObjectStruct := InsertLine(myLine, pObjectStruct);
  399.         end;
  400.         if (global gDebugFlag)
  401.             println "This is the pObjectStruct after SetLine - ", pObjectStruct;
  402.     end;
  403.     else
  404.     begin
  405.         if (global gDebugFlag)
  406.             LogStr("This is not a tool that supports different line weights");
  407.         pObjectStruct := InsertLine(0, pObjectStruct);
  408.     end;
  409.     
  410.     ##### SetColor ######
  411.     if(GetColorFlag(elemStruct))
  412.     begin
  413.         theCol := GetColor(pObjectStruct);
  414.         if(theCol)
  415.         begin
  416.             theColor := Call(gSetColor, theCol,,pDrawObject);
  417.             pObjectStruct := InsertColor(theColor,pObjectStruct); #
  418.             #pObjectStruct := InsertColor(SetColor(theCol),pObjectStruct); # VU 1.1 call
  419.         end;
  420.         if (global gDebugFlag)
  421.             println "This is the pObjectStruct after SetColor - ", pObjectStruct;
  422.     end;
  423.     else
  424.     begin
  425.         if (global gDebugFlag)
  426.             LogStr("This is not a color tool");
  427.         pObjectStruct := InsertColor(0, pObjectStruct);
  428.     end;
  429.     
  430.     return(pObjectStruct);
  431. end;    # SetAttributes()
  432.  
  433. #########################################################################
  434. #                            UseClickTool()
  435. #========================================================================
  436. # Author:        David Matzner (x41220)
  437. # Description:    Click once at the current mouse location.
  438. # Parameters:    None
  439. # Returns:        1 - Clicked
  440. # Examples:        UseClickTool();
  441. # Assumptions:    None 
  442. #========================================================================
  443. # History:
  444. #
  445. #########################################################################
  446. TASK UseClickTool() begin
  447.     if (global gDebugFlag)
  448.         println "----- UseClickTool() - Draw.lib --------";
  449.  
  450.     click;    # already at first point - do first click
  451.     LogStr("Clicked the mouse button");
  452.     return(1);
  453. end;
  454.  
  455. #########################################################################
  456. #            UseDragTool(pPoint, pSpecifier, pMouseDown, pDClickToEnd)
  457. #========================================================================
  458. # Author:        David Matzner (x41220)
  459. # Description:    Drag from the current location.
  460. # Parameters:    pPoint - Point to move to.
  461. #                pSpecifier - Window specifier in which to drag in.
  462. #                pMouseDown - 0 - don't hold mouse key down while moving
  463. #                            1 - press mouse key down - move - release
  464. #                            2 - Click after moving - no mouse down during move
  465. #                            3 - press mouse key down - move - don't release
  466. #                            4 - move - release
  467. #                pDClickToEnd - Boolean flag indicating whether or not to double
  468. #                                click the mouse after dragging.
  469. # Returns:        returnVal - what moveRelativeToWindow returns.
  470. # Examples:        UseDragTool({100,200}, 0, 1,0);
  471. # Assumptions:    Mouse positioned at start point on entry.  All points are
  472. #                 specified relative to window.
  473. #========================================================================
  474. # History:
  475. #
  476. #########################################################################
  477. TASK UseDragTool(pPoint:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0) 
  478. begin
  479.     if (global gDebugFlag)
  480.         println "----- UseDragTool() - Draw.lib --------";
  481.     returnVal := 0;
  482.     h := pPoint[1];
  483.     v := pPoint[2];
  484.     if (global gDebugFlag)
  485.         Println "Using the drag tool, {h}, {v}";
  486.     returnVal := MoveRelativeToWindow( h , v , pSpecifier, pMouseDown);
  487.     if (pDClickToEnd) begin    # doubleClick to end sequence
  488.         doubleClick;
  489.         #LogStr("Double-clicked the mouse button to end drawing sequence");
  490.     end;
  491.  
  492.     return(returnVal);
  493. end;
  494.  
  495. #########################################################################
  496. #    UseDragClickTool(pPointList, pSpecifier, pMouseDown, pDClickToEnd)
  497. #========================================================================
  498. # Author:        Kevin Avoy (x45604)
  499. # Description:    Drag from the current location. Then click at a different point.
  500. # Parameters:    pPointList - List of points to move to.
  501. #                pSpecifier - Window specifier in which to drag in.
  502. #                pMouseDown - 0 - don't hold mouse key down while moving
  503. #                            1 - press mouse key down - move - release
  504. #                            2 - Click after moving - no mouse down during move
  505. #                            3 - press mouse key down - move - don't release
  506. #                            4 - move - release
  507. #                pDClickToEnd - Boolean flag indicating whether or not to double
  508. #                                click the mouse after dragging.
  509. # Returns:        returnVal - what MoveRelativeToWindow returns.
  510. # Examples:        UseDragClickTool({{100,200}, {200,300}},0,1,0);
  511. # Assumptions:    Mouse positioned at start point on entry.  All points are
  512. #                 specified relative to window.
  513. #========================================================================
  514. # History:
  515. #
  516. #########################################################################
  517. TASK UseDragClickTool(pPointList:= {}, pSpecifier := 0, pMouseDown := 1, pDClickToEnd := 0)
  518. begin
  519.     if (global gDebugFlag)
  520.     begin
  521.         println "----- UseDragClickTool() - Draw.lib --------";
  522.         println "pPointList - ", pPointList;
  523.     end;
  524.     returnVal := 0;
  525.     dragPt := pPointList[1];
  526.     clickPt := pPointList[2];
  527.  
  528.     dragH := dragPt[1];
  529.     dragV := dragPt[2];
  530.     clickH := clickPt[1];
  531.     clickV := clickPt[2];
  532.     if (global gDebugFlag)
  533.         Println "Using the dragClick tool";
  534.     returnVal := MoveRelativeToWindow( dragH , dragV , pSpecifier, pMouseDown);
  535.     returnVal := MoveRelativeToWindow( clickH ,clickV , pSpecifier, 2);
  536.     if (pDClickToEnd) 
  537.     begin    # doubleClick to end sequence
  538.         doubleClick;
  539.         #LogStr("Double-clicked the mouse button to end drawing sequence");
  540.     end;
  541.  
  542.     return(returnVal);
  543. end; # UseDragClickTool()
  544.  
  545. #########################################################################
  546. #            UseMultiDragTool(pPointList, pSpecifier, pDClickToEnd)
  547. #========================================================================
  548. # Author:        David Matzner (x41220)
  549. # Description:    mouseDown-drag-drag-drag-drag-release.
  550. # Parameters:    pPointList - List of points to move to.
  551. #                pSpecifier - Window specifier in which to drag in.
  552. #                pDClickToEnd - Boolean flag indicating whether or not to double
  553. #                                click the mouse after dragging.
  554. # Returns:        returnVal - what MoveRelativeToWindow returns.
  555. # Examples:        UseMultiDragTool({{100,200}, {200,300}},0,0);
  556. # Assumptions:    Mouse positioned at start point on entry.  All points are
  557. #                 specified relative to window.
  558. #========================================================================
  559. # History:
  560. #
  561. #########################################################################
  562. TASK UseMultiDragTool(pPointList := {}, pSpecifier := 0, pDClickToEnd := 0) 
  563. begin
  564.     if (global gDebugFlag)
  565.         println "----- UseMultiDragTool() - Draw.lib --------";
  566.     returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier,3);
  567.     if (pDClickToEnd) 
  568.     begin    # doubleClick to end sequence
  569.         doubleClick;
  570.         #LogStr("Double-clicked the mouse button to end drawing sequence");
  571.     end;
  572.  
  573.     return(returnVal);
  574. end;
  575.  
  576. #########################################################################
  577. #        UseMultiClickTool(pPointList, pSpecifier, pDClickToEnd)
  578. #========================================================================
  579. # Author:        David Matzner (x41220)
  580. # Description:    click-move-click-move….
  581. # Parameters:    pPointList - List of points to move to.
  582. #                pSpecifier - Window specifier in which to drag in.
  583. #                pDClickToEnd - Boolean flag indicating whether or not to double
  584. #                                click the mouse after dragging.
  585. # Returns:        returnVal - what MoveRelativeToWindow returns.
  586. # Examples:        UseMultiClickTool({{100,200}, {200,300}},0,0);
  587. # Assumptions:    Mouse positioned at start point on entry.  All points are
  588. #                 specified relative to window.
  589. #========================================================================
  590. # History:
  591. #
  592. #########################################################################
  593. TASK UseMultiClickTool(pPointList, pSpecifier := 0, pDClickToEnd := 0) 
  594. begin
  595.     if (global gDebugFlag)
  596.         println "----- UseMultiClickTool() - Draw.lib --------";
  597.     returnVal := MoveRelativeToWindow( pPointList ,, pSpecifier, 5);
  598.     
  599.     if (pDClickToEnd) 
  600.     begin                    # doubleClick to end sequence
  601.         doubleClick;
  602.         #LogStr("Double-clicked the mouse button to end drawing sequence");
  603.     end;
  604.     return(returnVal);
  605. end;
  606.  
  607. #########################################################################
  608. #    UseMultiClickDragTool(pPointList, pSpecifier, pDClickToEnd)
  609. #========================================================================
  610. # Author:        David Matzner (x41220)
  611. # Description:    mouseDown-drag-mouseUp-mouseDown-drag-mouseUp….
  612. # Parameters:    pPointList - List of points to move to.
  613. #                pSpecifier - Window specifier in which to drag in.
  614. #                pDClickToEnd - Boolean flag indicating whether or not to double
  615. #                                click the mouse after dragging.
  616. # Returns:        Nothing
  617. # Examples:        UseMultiClickDragTool();
  618. # Assumptions:    Mouse positioned at start point on entry.  All points are
  619. #                 specified relative to window.
  620. #========================================================================
  621. # History:
  622. #
  623. #########################################################################
  624. TASK UseMultiClickDragTool(pPointList, pSpecifier := 0, pDClickToEnd := 0) 
  625. begin
  626.     if (global gDebugFlag)
  627.         println "----- UseMultiClickDragTool() - Draw.lib --------";
  628.     oldMouseSpeed := mouseSpeed(4);    # slow down mouse
  629.     mouseDown := 4;
  630.     
  631.     for each pt in pPointList
  632.         UseDragTool(pt, pSpecifier, mouseDown);
  633.         
  634.     mouseSpeed(oldMouseSpeed);        # restore mouse speed
  635.     if (pDClickToEnd) 
  636.     begin                    # doubleClick to end sequence
  637.         doubleClick;
  638.         #LogStr("Double-clicked the mouse button to end drawing sequence");
  639.     end;
  640. end;
  641.  
  642. #########################################################################
  643. #                            Object Structure Accessors()
  644. #========================================================================
  645. # Author:        David Matzner (x41220)
  646. # Description:    These functions access the data in an objectStruct data 
  647. #                structure.
  648. # Parameters:    objectStruct
  649. # Returns:        the requested data element or list
  650. #========================================================================
  651. # History:
  652. #
  653. #########################################################################
  654. ## objectStruct is the data structure that completely specifies the object to be drawn
  655. ##            objectStruct    {
  656. ##                ElemStruct
  657. ##                PointList
  658. ##                Pattern
  659. ##                Line
  660. ##                Color
  661. ##            }
  662.  
  663. task GetElemStruct(objectStruct)     begin return( objectStruct[1] );    end;
  664. task GetPointList(objectStruct)        begin return( objectStruct[2] );    end;
  665. task GetPattern(objectStruct)        begin return( objectStruct[3] );    end;
  666. task GetLine(objectStruct)            begin return( objectStruct[4] );    end;
  667. task GetColor(objectStruct)            begin return( objectStruct[5] );    end;
  668.  
  669. task InsertElemStruct(tS, oS)        begin return( replace( tS,  1, oS ));    end;
  670. task InsertPointList(pts, oS)        begin return( replace( pts, 2, oS ));    end;
  671. task InsertPattern(pat, oS)            begin return( replace( pat, 3, oS ));    end;
  672. task InsertLine(lin, oS)            begin return( replace( lin, 4, oS ));    end;
  673. task InsertColor(col, oS)            begin return( replace( col, 5, oS ));    end;
  674.  
  675.  
  676. #########################################################################
  677. #        MakePointList( pInset, pSpecifier, pNumPoints, pClosed, pVoidRect )
  678. #========================================================================
  679. # Author:        David Matzner
  680. # Description:    Generates a list of random points 
  681. # Parameters:    pInset -     inset into window for ppoints to be generated.
  682. #                pSpecifier - Window specifier for the window to generate points in.
  683. #                pNumPoints -    number of points to comprise the object
  684. #                pClosed     -     1 for closed object (first-last point the same)
  685. #                            0 for open object (first-last point different)
  686. #                pVoidRect - no points in object should be in this rectangle 
  687. # Returns:        List of Points.
  688. # Examples:        theObject := MakePointList(rect);    # 4 point closed object
  689. #                theObject := MakePointList(theWindow.r, 4,1,thePalette.r);
  690. #========================================================================
  691. # History:
  692. #
  693. ########################################################################
  694. TASK MakePointList(pInset :={ 0,20,20,20 } , pSpecifier := 0, pNumPoints := global gNumPoints,  pClosed := 0, pVoidRect := {} ) 
  695. begin
  696.     if (global gDebugFlag)
  697.         println "----- MakePointList() - Draw.lib --------";
  698.     global gWindowInset, gVoidRect,gNumPoints, gBoundingRect;
  699.     # To help assure drawing occurs in the content region
  700.     if (gBoundingRect)                        # Window Rect
  701.         boundingRect := gBoundingRect;
  702.     else 
  703.         boundingRect := pSpecifier;
  704.         
  705.     if (gWindowInset)                        # Window inset
  706.         pInset := gWindowInset;
  707.     if (gVoidRect)                            # No points will be in this rect - 
  708.         pVoidRect := gVoidRect;                # Coordinates should be relative to window
  709.     pointList := GetRandomPointsRelativeToWindow(pInset, boundingRect,pNumPoints);
  710.     if (pNumPoints = 1)        # When only one set of point is required
  711.         pointlist := { pointlist };
  712.  
  713.     # Last point is same as first
  714.     if(pClosed)
  715.         pointList := replace(pointList[1], pNumPoints, pointList );
  716.     
  717.     # only points that are not in the void rectangle
  718.     if (pVoidRect) 
  719.     begin
  720.         for x := 1 to (pNumPoints - pClosed)     # last point will equal first if closed is true
  721.         begin
  722.             while (PtInRect(pointList[x],pVoidRect)) 
  723.             begin
  724.                 thePointh := pointList[x][1];
  725.                 thePointv := pointList[x][2];
  726.                 if (global gDebugFlag)
  727.                     Println "{thePointh},{thePointv} is in the void rect - get another point";
  728.                 thePoint := GetRandomPointsRelativeToWindow(pInset, boundingRect);
  729.                 if (thePoint) pointList := replace(thePoint, x, pointList );
  730.                 else LogStr("GetRandomPointsRelativeToWindow() hosed");
  731.             end;
  732.         end;
  733.     end;
  734.     
  735.     return( pointList );
  736. end; # MakePointList()
  737.  
  738.  
  739. #########################################################################
  740. #                    SetTool(pTool,pSelectTool, pObjectNumber)
  741. #========================================================================
  742. # Author:        Kevin Avoy (x45604)
  743. # Description:    This task takes a ToolStruct as a parameter. If the ToolStruct
  744. #                evaluates to 'Random' a ToolStruct will be generated randomly.
  745. #                If the pSelectTool evaluates to true the tool will also be selected.
  746. #                Otherwise, the generated toolStruct will be returned without 
  747. #                selecting the tool. 
  748. # Parameters:    pTool - 0 - nothing done return 0
  749. #                        - Valid ToolStruct
  750. #                        - 'Random' - generates a random ToolStruct
  751. #                pSelectTool - Boolean flag which indicates whether or not to 
  752. #                            select the tool.
  753. #                pObjectNumber - Integer used to track all elements that make up 
  754. #                                an object - TCS related.
  755. # Returns:        0 - nothing done 0 passed in.
  756. #                Valid toolStruct 
  757. # Assumptions:    All draw related data structures set up properly.
  758. #========================================================================
  759. # History:
  760. #
  761. #########################################################################
  762. TASK SetTool(pTool := 'Random', pSelectTool := 1, pObjectNumber := 0)
  763. begin
  764.     if (global gDebugFlag)
  765.     begin
  766.         Println "++++++++ SetTool() has just been called++++++++ ";
  767.         Println "This is the toolStruct - ",pTool;
  768.     end;
  769.     global gToolList;
  770.     if(pTool)
  771.     begin
  772.         if(pTool = 'Random')
  773.         begin
  774.             toolNum := Random(1,card(gToolList));
  775.             pTool := gToolList[toolNum];
  776.             #theObject := InsertElemStruct(pTool, theObject); # Insert the tool description
  777.             if (global gDebugFlag)
  778.                 println "    pTool after generating a random one in SetTool() - ", pTool;
  779.         end;
  780.         if (pSelectTool)
  781.         begin
  782.             PalettePicker(pTool,pObjectNumber);
  783.             # This is where we put a hook for Dragging tools after selecting
  784.         end;
  785.     end;
  786.     return(pTool);
  787. end;
  788.  
  789. #########################################################################
  790. #                        GenerateObject(pTheObject)
  791. #========================================================================
  792. # Author:        Kevin Avoy
  793. # Description:    This task generates valid elements for any element that evaluates
  794. #                to 'Random'. 
  795. # Parameters:    pTheObject - A complete Object Struct.  The default is to 
  796. #                            generate all elements of the returned object
  797. #                            randomly. Passing in partially completed object
  798. #                            struct will replace the elements which evaluate
  799. #                            to 'Random' with valid data.
  800. # Returns:        pTheObject - a complete objectStruct no elements will evaluate
  801. #                            to 'Random'
  802. # Examples:        GenerateObject({global PointerTool,'Random',0,'Random','Random'})
  803. # Assumptions:    All the necessary Draw Structs have been defined correctly.
  804. #========================================================================
  805. # History:
  806. #
  807. #########################################################################
  808. TASK GenerateObject(pTheObject := {'Random','Random','Random','Random','Random'}) 
  809. begin
  810.     if (global gDebugFlag)
  811.         Println "----- GenerateObject() - Draw.lib --------";
  812.  
  813.     theTool := GetElemStruct(pTheObject);
  814.     if (theTool = 'Random')
  815.         theTool := SetTool(theTool, 0);
  816.     pTheObject := InsertElemStruct(theTool,pTheObject);
  817.     
  818.     thePointList := GetPointList(pTheObject);
  819.     if (thePointList = 'Random')
  820.         thePointList := SetPointList(pTheObject);
  821.     pTheObject := InsertPointList(thePointList, pTheObject);
  822.  
  823.     thePattern := GetPattern(pTheObject);
  824.     if (thePattern = 'Random')
  825.         thePattern := SetPattern(thePattern, 0);
  826.     pTheObject := InsertPattern(thePattern,pTheObject);
  827.  
  828.     theLine := GetLine(pTheObject);
  829.     if (theline = 'Random')
  830.         theLine := SetLine(theLine, 0);
  831.     pTheObject := InsertLine(theLine,pTheObject);
  832.  
  833.     theColor := GetColor(pTheObject);
  834.     if (theColor = 'Random')
  835.         theColor := SetColor(theColor, 0);
  836.     pTheObject := InsertColor(theColor,pTheObject);
  837.  
  838.         Return(pTheObject);
  839. end; # GenerateObject()
  840.  
  841. #########################################################################
  842. #                        SetPointList(pTheObject, pSpecifier)
  843. #========================================================================
  844. # Author:        Kevin Avoy (x45604)
  845. # Description:    Determines the number of points required for a given tool type.
  846. #                Then calls MakePointList() to generate pointlist for different
  847. #                tool types.
  848. #                    kClick tools - require a single point.
  849. #                    kDrag tools - require a two points.
  850. #                    All multipoint tools - access the global gNumPoints to 
  851. #                        determine the number of points.
  852. # Parameters:    pTheObject - a complete objectStruct with atleast a valid
  853. #                            ToolStruct. 
  854. #                pSpecifier - Specifier of the window in which to generate 
  855. #                             points in.
  856. # Returns:        thePointList - a list of point within <pSpecifier>
  857. # Examples:        SetPointList(TheObjectStruct, 0);
  858. # Assumptions:    All the necessary Draw Structs have been defined correctly.
  859. #========================================================================
  860. # History:
  861. #
  862. #########################################################################
  863. TASK SetPointList(pTheObject, pSpecifier := 0)
  864. begin
  865.     global gNumPoints;
  866.     if (global gDebugFlag)
  867.         Println "++++++++ SetPointList() has just been called++++++++ ";
  868.     theTool := GetElemStruct(pTheObject);
  869.     thePointList := GetPointList(pTheObject);
  870.     if(theTool)
  871.     begin
  872.         if (thePointList)
  873.         begin
  874.             if(thePointList = 'Random')
  875.             begin
  876.                 elemType := GetElemType(theTool);
  877.                 if(elemType)
  878.                 begin
  879.                     # Create a point list and insert into the object structure 
  880.                     # The number of points depends on the tool
  881.                     elemType := GetElemType(theTool);
  882.                     if (elemType <= 3) numPoints := elemType; # Click - pointlist will be 1/drag - pointlist will be 2
  883.                     else numPoints := gNumPoints;
  884.                     
  885.                     thePointList := MakePointList(,pSpecifier,numPoints);
  886.                 end;
  887.                 else
  888.                     thePointList := 0;
  889.             end;
  890.         end;
  891.     end;
  892.     else
  893.         println "Sorry, can't generate a pointlist unless a tool has been defined";
  894.         
  895.     return(thePointList);
  896. end; # SetPointList()
  897.  
  898. #########################################################################
  899. #    Draw(pTheTool, pThePointList, pThePattern, pTheLine, pTheColor, pSpecifier )
  900. #========================================================================
  901. # Author:        Kevin Avoy
  902. # Description:    This task provides a means for defining any of the elements
  903. #                within an ObjectStruct and allowing the libraries to generate
  904. #                any element that evaluates to 'Random' (default for all elements)
  905. # Parameters:    1 parameter for each of the elements of an objectStruct and 
  906. #                1 additional parameter for the window pSpecifier.
  907. #                    pTheTool - ToolStruct
  908. #                    pThePointList - PointList (not user definable at this time)
  909. #                    pThePattern - PatternStruct
  910. #                    pTheLine - LineStruct
  911. #                    pTheColor - ColorStruct
  912. #                    pSpecifier - Window or rect to draw in 
  913. # Returns:        The actual ObjectStruct after generating 'Random' elements.
  914. # Examples:        Draw(Global SelectTool, ‘Random’,0,0,{14,3, ‘Color’})
  915. # Assumptions:    All the necessary Draw Structs have been defined correctly.
  916. #========================================================================
  917. # History:
  918. #
  919. #########################################################################
  920. TASK Draw(pTheTool := 'Random', pThePointList := 'Random', pThePattern := 'Random', pTheLine := 'Random', pTheColor := 'Random', pSpecifier := 0)
  921. begin
  922.     theObject := {'Random','Random','Random','Random','Random'};
  923.  
  924.     if not(pTheTool = 'Random')
  925.         theObject := InsertElemStruct(pTheTool, theObject);
  926.  
  927.     #if not(pThePointList = 'Random')    # We want to generate all pointlists for now KTA 7/92
  928.         #theObject := InsertPointList(pThePointList, theObject);
  929.  
  930.     if not(pThePattern = 'Random')
  931.         theObject := InsertPattern(pThePattern, theObject);
  932.  
  933.     if not(pTheLine = 'Random')
  934.         theObject := InsertLine(pTheLine, theObject);
  935.  
  936.     if not(pTheColor = 'Random')
  937.         theObject := InsertColor(pTheColor, theObject);
  938.  
  939.     theObject := DrawObject(theObject, pSpecifier);
  940.     return(theObject);
  941. end;
  942.  
  943. #########################################################################
  944. #                SetColor(pTheColor, pSelectColor, pObjectNumber)
  945. #========================================================================
  946. # Author:        Kevin Avoy
  947. # Description:    This is used when selecting colors from a palette.This task
  948. #                takes a ColorStruct as a parameter. If the ColorStruct evaluates
  949. #                to 'Random' a ColorStruct will be generated randomly.
  950. #                If the pSelectColor evaluates to true the color will also be selected.
  951. #                Otherwise, the generated ColorStruct will be returned without 
  952. #                selecting the color.  
  953. # Parameters:    pTheColor - 0 - nothing done return 0
  954. #                        - Valid ColorStruct
  955. #                        - 'Random' - generates a random ColorStruct
  956. #                pSelectColor - Boolean flag which indicates whether or not to 
  957. #                            select the Color.
  958. #                pObjectNumber - Integer used to track all elements that make up 
  959. #                                an object - TCS related.
  960. # Returns:        colStruct - A valid ColorStruct
  961. # Examples:        SetColor('Random', 1, 14);
  962. # Assumptions:    All draw related data structures set up properly.
  963. #========================================================================
  964. # History:
  965. #
  966. #########################################################################
  967. TASK SetColor(pTheColor := 'Random', pSelectColor := 1, pObjectNumber := 0)    
  968. begin
  969.     if (global gDebugFlag)
  970.     begin
  971.         Println "++++++++ SetColor() has just been called++++++++ ";
  972.         Println "This is the colStruct - ",pTheColor;
  973.     end;
  974.     global gPaletteList, kColorPaletteNum;
  975.     if (gPaletteList) and (kColorPaletteNum)
  976.     begin
  977.         if(pTheColor)
  978.         begin
  979.             if(pTheColor = 'Random')     #  Random Color
  980.             begin                    
  981.                 thePalette := gPaletteList[kColorPaletteNum];
  982.                 pTheColor := GetRandomElement(thePalette);
  983.             end;
  984.             if (TypeOf(pTheColor) = 'integer')
  985.                 colStruct := { pTheColor, kColorPaletteNum, "Color"};    # create a struct to send to the palette picker
  986.             else
  987.                 colStruct := pTheColor;
  988.     
  989.             if(colStruct) and (pSelectColor)
  990.                 PalettePicker(colStruct, pObjectNumber);
  991.         end;
  992.         else
  993.             colStruct := 0;
  994.     end;
  995.     else
  996.     begin
  997.         colStruct := 0;
  998.         if (global gDebugFlag)
  999.             Println "Either the gPaletteList or the kColorPaletteNum is not defined";
  1000.     end;
  1001.     return(colStruct);
  1002. end; # SetColor()
  1003.  
  1004.  
  1005. #########################################################################
  1006. #                    SetLine(pTheLine, pSelectLine, pObjectNumber)
  1007. #========================================================================
  1008. # Author:        Kevin Avoy
  1009. # Description:    This is used when selecting line weights from a palette. 
  1010. #                This task takes a LineStruct as a parameter. If the LineStruct
  1011. #                evaluates to 'Random' a LineStruct will be generated randomly.
  1012. #                If the pSelectLine evaluates to true the line will also be selected.
  1013. #                Otherwise, the generated LineStruct will be returned without 
  1014. #                selecting the line weight.
  1015. # Parameters:    pTheLine - 0 - nothing done return 0
  1016. #                        - Valid LineStruct
  1017. #                        - 'Random' - generates a random LineStruct
  1018. #                pSelectLine - Boolean flag which indicates whether or not to 
  1019. #                            select the line.
  1020. #                pObjectNumber - Integer used to track all elements that make up 
  1021. #                                an object - TCS related.
  1022. # Returns:        LineStruct - A valid LineStruct
  1023. # Examples:        SetLine('Random', 1, 14);
  1024. # Assumptions:    All draw related data structures set up properly.
  1025. #========================================================================
  1026. # History:
  1027. #
  1028. #########################################################################
  1029. TASK SetLine(pTheLine := 'Random', pSelectLine := 1, pObjectNumber := 0) 
  1030. begin
  1031.     if (global gDebugFlag)
  1032.     begin
  1033.         Println "++++++++ SetLine() has just been called +++++++++";
  1034.         Println "This is the LineStruct - ",pTheLine;
  1035.     end;
  1036.     global gPaletteList, kLinePaletteNum;
  1037.     if (gPaletteList) and (kLinePaletteNum)
  1038.     begin
  1039.         if(pTheLine)
  1040.         begin
  1041.             if(pTheLine = 'Random')         # Random Line
  1042.             begin                            
  1043.                 thePalette := gPaletteList[kLinePaletteNum];
  1044.                 pTheLine := GetRandomElement(thePalette);
  1045.             end;
  1046.             if (TypeOf(pTheLine) = 'integer')
  1047.                 LineStruct := { pTheLine, kLinePaletteNum, "Line"};    # create a struct to send to the palette picker
  1048.             else
  1049.                 LineStruct := pTheLine;
  1050.                 
  1051.             if(LineStruct) and (pSelectLine)
  1052.                 PalettePicker(LineStruct, pObjectNumber);
  1053.         end;
  1054.         else
  1055.             LineStruct := 0;
  1056.     end;
  1057.     else
  1058.     begin
  1059.         LineStruct := 0;
  1060.         if (global gDebugFlag)
  1061.             Println "Either the gPaletteList or the kLinePaletteNum is not defined";
  1062.     end;
  1063.     
  1064.     return(LineStruct);
  1065. end; # SetLine()
  1066.  
  1067. #########################################################################
  1068. #                    SetLine(pTheLine, pSelectLine, pObjectNumber)
  1069. #========================================================================
  1070. # Author:        Kevin Avoy
  1071. # Description:    This is used when selecting line weights from menuItems. 
  1072. #                This task takes a LineStruct as a parameter. If the LineStruct
  1073. #                evaluates to 'Random' a LineStruct will be generated randomly.
  1074. #                If the ppSelectLine evaluates to true the tool will also be selected.
  1075. #                Otherwise, the generated LineStruct will be returned without 
  1076. #                selecting the line weight.  This task depends upon a global
  1077. #                gLineWeights to be defined as the menuItem titles of the menuitems
  1078. #                which are used to set line wieghts.
  1079. # Parameters:    pTheLine - 0 - nothing done return 0
  1080. #                        - Valid LineStruct
  1081. #                        - 'Random' - generates a random LineStruct
  1082. #                pSelectLine - Boolean flag which indicates whether or not to 
  1083. #                            select the line.
  1084. #                pObjectNumber - Integer used to track all elements that make up 
  1085. #                                an object - TCS related.
  1086. # Returns:        LineStruct - A valid LineStruct
  1087. # Examples:        SetLine('Random', 1, 14);
  1088. # Assumptions:    All draw related data structures set up properly.
  1089. #========================================================================
  1090. # History:
  1091. # KTA    8/24/93        TCS stack parity check
  1092. #########################################################################
  1093. TASK SetLineMenuItems(pTheLine := {}, pSelectLine := 1,  pObjectNumber := 0) 
  1094. begin
  1095.     failStr := '';
  1096.     if (global gDebugFlag)
  1097.         println "++++++++ SetLine() has just been called++++++++ ";
  1098.     global gLineWeights;
  1099.     if(pTheLine) 
  1100.     begin    
  1101.         # If a weight is not passed then calculate a random one
  1102.         if(pTheLine = 'Random')                        # Random Line wieght    
  1103.         begin
  1104.             whichWeight := random(1, Card(gLineWeights));    # Calculate which random weight to use
  1105.             TheLineWeight := gLineWeights[whichWeight];        # Set variable to actual weight
  1106.             pTheLine := { TheLineWeight, "Menu Item", "Line"};
  1107.             #theObject := InsertLine(lineStruct, theObject); 
  1108.         end;
  1109.         else
  1110.             TheLineWeight := pTheLine[1];
  1111.         
  1112.         
  1113.         if(TheLineWeight) and (pSelectLine)
  1114.         begin
  1115.             TCSStart({ 1, global kTCSetDraw },"SetLineMenuItems");        # Start TCS
  1116.             returnVal := SelectMenuItem(TheLineWeight);            # Select it
  1117.             if (returnVal)
  1118.                 returnVal := 1;
  1119.             else
  1120.             begin
  1121.                 failStr := "Failed to select menu item for line weight";
  1122.                 LogStr(failStr);
  1123.             end;
  1124.             TCSEnd({ 1, global kTCSetDraw },returnVal,failStr,pObjectNumber,TheLineWeight);
  1125.         end;
  1126.     end;
  1127.     else
  1128.         LogStr("Null object passed to SetLine");
  1129.     return(pTheLine);
  1130. end; # SetLineMenuItems()
  1131.  
  1132. #########################################################################
  1133. #            SetPattern(pThePattern, pSelectPattern, pObjectNumber)
  1134. #========================================================================
  1135. # Author:        Kevin Avoy
  1136. # Description:    This is used when selecting patterns from a palette. 
  1137. #                This task takes a PatternStruct as a parameter. If the PatternStruct
  1138. #                evaluates to 'Random' a PatternStruct will be generated randomly.
  1139. #                If the pSelectPattern evaluates to true the pattern will also be selected.
  1140. #                Otherwise, the generated PatternStruct will be returned without 
  1141. #                selecting the pattern.
  1142. # Parameters:    pThePattern - 0 - nothing done return 0
  1143. #                            - Valid PatternStruct
  1144. #                            - 'Random' - generates a random PatternStruct
  1145. #                pSelectPattern - Boolean flag which indicates whether or not to 
  1146. #                            select the pattern.
  1147. #                pObjectNumber - Integer used to track all elements that make up 
  1148. #                                an object - TCS related.
  1149. # Returns:        patStruct - A valid PatternStruct
  1150. # Examples:        SetPattern('Random', 1, 14);
  1151. # Assumptions:    All draw related data structures set up properly.
  1152. #========================================================================
  1153. # History:
  1154. #
  1155. #########################################################################
  1156. TASK SetPattern(pThePattern := 'Random', pSelectPattern := 1, pObjectNumber := 0)    
  1157. begin
  1158.     if (global gDebugFlag)
  1159.     begin
  1160.         Println "++++++++ SetPattern() has just been called +++++++++";
  1161.         Println "This is the PatStruct - ",pThePattern;
  1162.     end;
  1163.     global gPaletteList, kPatternPaletteNum;
  1164.     if (gPaletteList) and (kPatternPaletteNum)
  1165.     begin
  1166.         if(pThePattern)
  1167.         begin
  1168.             if(pThePattern = 'Random') # Random pattern
  1169.             begin                                
  1170.                 thePalette := gPaletteList[kPatternPaletteNum];
  1171.                 pThePattern := GetRandomElement(thePalette);
  1172.             end;
  1173.             if (TypeOf(pThePattern) = 'integer')
  1174.                     patStruct := { pThePattern, kPatternPaletteNum, "Pattern"};    # create a struct to send to the palette picker
  1175.             else
  1176.                 patStruct := pThePattern;
  1177.     
  1178.             if(patStruct) and (pSelectPattern)
  1179.                 PalettePicker(patStruct, pObjectNumber);
  1180.         end;
  1181.         else
  1182.             patStruct := 0;
  1183.     end;
  1184.     else
  1185.     begin
  1186.         patStruct := 0;
  1187.         if (global gDebugFlag)
  1188.             Println "Either the gPaletteList or the kPatternPaletteNum is not defined";
  1189.     end;
  1190.     return(patStruct);
  1191. end; # SetPattern()
  1192.  
  1193. #########################################################################
  1194. #                    CheckSetup()
  1195. #========================================================================
  1196. # Author:        Kevin Avoy
  1197. # Description:    Reports the current state of various draw related
  1198. #                globals and global structures.  Call this task after a script    
  1199. #                has defined all of its draw related globals.  This routine will 
  1200. #                print the current setting.  A review of the output could help
  1201. #                to reveal any problems with the initial setup.
  1202. # Parameters:    none
  1203. # Returns:        nothing
  1204. # Examples:        CheckSetup();
  1205. #========================================================================
  1206. # History:
  1207. #
  1208. #########################################################################
  1209. TASK CheckSetup()
  1210. begin
  1211.     global kPalDocWind, kPalWind, kPullOffPal, kPopUpPal, kScrollPal;
  1212.  
  1213.     Println "The Bounding Rect is - ", global gBoundingRect;        # Window inset
  1214.     Println "The Void Rect is - ", global gVoidRect;    # Rect not to draw in - coordinates should be RelativeToWindow
  1215.     Println "The Number of point that all multipoint object will be drawn is  - '{global gNumPoints}'";
  1216.     Println "The Global TextStr is - '{global gTextStr}'";
  1217.     For i := 1 to Card(global gPaletteList)
  1218.     begin 
  1219.         CurrentPalette := gPaletteList[i];
  1220.         Println;
  1221.         if (CurrentPalette[2] = kPopUpPal)
  1222.         begin
  1223.             PopPoint := {CurrentPalette[1][1],CurrentPalette[1][2]}; 
  1224.             Println "•• Palette number - '{i}' is a popup Palette with a poppoint at ",PopPoint;
  1225.             TLFirstElem := {CurrentPalette[1][3],CurrentPalette[1][4]}; 
  1226.             Println "•• The TopLeft of first elem is ",TLFirstElem;
  1227.             if (Card(CurrentPalette[1]) = 4)
  1228.                 Println "•• The popPoint and TopLeft coordinates are relative to the front window";
  1229.             else if (Card(CurrentPalette[1]) = 5)
  1230.                 Println "•• The popPoint and TopLeft coordinates are absolute";
  1231.             Println "•• It is type - ",CurrentPalette[2], " which is a kPopUpPal ( pop up palette )";
  1232.         end;
  1233.         else if (CurrentPalette[2] = kPalWind)
  1234.         begin
  1235.             Println "•• Palette number - '{i}' has the specifier of - ",CurrentPalette[1][1];
  1236.             Println "•• It is type - ",CurrentPalette[2], " which is a kPalWind ( palette contained within its own window )";
  1237.             Println "•• The vertical distance between the top of the window and the top of the 1st tool is - ", CurrentPalette[1][2];
  1238.         end;
  1239.         else
  1240.             Println "•• Palette number - '{i}' has the Coordinates of - ",CurrentPalette[1];
  1241.  
  1242.         if (CurrentPalette[2] = kPalDocWind)
  1243.             Println "•• It is type - ",CurrentPalette[2], " which is a kPalDocWind ( contained within a documents window )";
  1244.         else if (CurrentPalette[2] = kPullOffPal)
  1245.             Println "•• It is type - ",CurrentPalette[2], " which is a kPullOffPal ( Pull off and then it is contained within its own window )";
  1246.         else if (CurrentPalette[2] = kScrollPal)
  1247.             Println "•• It is type - ",CurrentPalette[2], " which is a kScrollPal ( Scrolling Palette (we don't handle yet))";
  1248.         
  1249.         Println "•• The size of the Tool matrix is - ", CurrentPalette[3];
  1250.         Println "•• The Offset between tools is  - ", CurrentPalette[4];
  1251.  
  1252.         Struct := { 1, i, "FirstItem"};    # create a struct to send to the palette picker
  1253.         PalettePicker(Struct);
  1254.         FinalTool := CurrentPalette[3][1] * CurrentPalette[3][2];
  1255.         Struct := { FinalTool, i, "LastItem"};    # create a struct to send to the palette picker
  1256.         PalettePicker(Struct);
  1257.         Println;
  1258.     end;
  1259.     global gToolList;
  1260. end; # CheckSetup()
  1261.